package com.wuzesheng.logger.controller;

import com.wuzesheng.logger.entity.Logger;
import com.wuzesheng.logger.response.MessageUtils;
import com.wuzesheng.logger.response.RestResponse;
import com.wuzesheng.logger.utils.KafkaTopicKeysUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 吴泽胜
 * @Date 2022/3/1 09:47
 * @Software IntelliJ IDEA
 * @Describe
 */
@RestController
@Slf4j
public class LoggerController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    private KafkaTopicKeysUtils kafkaTopicKeysUtils = new KafkaTopicKeysUtils();

    @GetMapping("test")
    public String test(){
        return "success";
    }

    @PostMapping("applog")
    public RestResponse get_realtime_applog(@RequestBody Logger logger){
        // 搜集日志
        log.info(logger.toString());

        // 落盘,通过lockback.xml 注入 log bean中

        // 发送到kafka
         kafkaTemplate.send( kafkaTopicKeysUtils.ODS_BASE_LOG, logger.toString());

        return MessageUtils.success();
    }
}
